package cn.wowjoy.office.common.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shizhefei.view.indicator.IndicatorViewPager;

import java.util.List;

import cn.wowjoy.office.R;
import cn.wowjoy.office.base.BaseFragment;
import cn.wowjoy.office.baselivedata.appbase.NewBaseFragment;

/**
 * Created by Sherily on 2017/9/7.
 */

public class TabIndicatorFragmentAdapter extends IndicatorViewPager.IndicatorFragmentPagerAdapter {
    private LayoutInflater inflater;
    private List<Integer> icons;
    private List<String> titles;
    private List<NewBaseFragment> fragments;

    public TabIndicatorFragmentAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
    }

    public void setData(List<Integer> icons,List<String> titles,List<NewBaseFragment> fragments){
        this.icons = icons;
        this.titles = titles;
        this.fragments = fragments;
        notifyDataSetChanged();

    }
    @Override
    public int getCount() {
        return null == icons ? 0 : icons.size();
    }

    @Override
    public View getViewForTab(int position, View convertView, ViewGroup container) {
        if (null == inflater)
            inflater = LayoutInflater.from(container.getContext());
        if (null == convertView)
            convertView = inflater.inflate(R.layout.tab_main, container, false);
        TextView textView = (TextView) convertView;
        textView.setText(titles.get(position));
        textView.setCompoundDrawablesWithIntrinsicBounds(0, icons.get(position), 0, 0);
        return textView;
    }

    @Override
    public Fragment getFragmentForPage(int position) {
        return fragments.get(position);
    }


}
